package com.hdoit.ares.web.weixin;

import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;

import org.junit.Test;

import com.tennetcn.common.selfcommon.message.wechat.Button;
import com.tennetcn.common.selfcommon.message.wechat.ComplexButton;
import com.tennetcn.common.selfcommon.message.wechat.Menu;
import com.tennetcn.common.selfcommon.message.wechat.ViewButton;
import com.tennetcn.common.utils.JsonUtils;

/**
 * 本文件用于设置公众号菜单
 * 创建人：小强同学
 */
public class WxMenuCreateTest03 {
	//@Test
	public void createMenu(){
		WxMpService wxService = new WxMpServiceImpl(); 
		wxService.setWxMpConfigStorage(getConfig());
		
		String appId=wxService.getWxMpConfigStorage().getAppId();
		String menuJson=getMenu(appId);	
		
		System.out.println(menuJson);
		
		try {
			String menuId=wxService.getMenuService().menuCreate(menuJson);
			System.out.println(menuId);
		} catch (Exception e) {
			
		}
	}
	
	private String getMenu(String appId){
//		永利共享商城的服务器
		String domain="http://www.putiyoli.net";
//		公司的服务器
//		String domain="http://www.hdoit.com";
//		我的1元服务器
//		String domain="http://www.putiyoli.net.cn";
		
		ViewButton exclusiveService = new ViewButton();
		exclusiveService.setName("专属服务");
		exclusiveService.setType("view");
		exclusiveService.setUrl(domain+"/ares/wechat/home/index");
		
	/*	ViewButton codePosterButton = new ViewButton();
		codePosterButton.setName("我的海报");
		String codePosterUrl = domain+"/ares/wechat/cust/invitation/shareRefresh";
		codePosterButton.setType("view");
		codePosterButton.setUrl(codePosterUrl);*/
		
		
		ViewButton myCodeButton = new ViewButton();
		myCodeButton.setName("我要分享");
		String discountViewUrl=domain+"/ares/wechat/cust/personCenter/shareCode";
		myCodeButton.setType("view");
		myCodeButton.setUrl(discountViewUrl);
		
		ViewButton myEntrepreneurButton = new ViewButton();
		myEntrepreneurButton.setName("加入创客");
		String entrepreneurViewUrl=domain+"/ares/wechat/cust/customerIden/joinEntrepreneur/";
		myEntrepreneurButton.setType("view");
		myEntrepreneurButton.setUrl(entrepreneurViewUrl);
		
		
		ComplexButton imSharedButton = new ComplexButton();
		imSharedButton.setName("我要创业");
		imSharedButton.setSub_button(new Button[] {myCodeButton,myEntrepreneurButton});
		
		
		ViewButton personCenter = new ViewButton();
		personCenter.setName("我的中心");
		String personCenterViewUrl=domain+"/ares/wechat/cust/personCenter/index";
		personCenter.setType("view");
		personCenter.setUrl(personCenterViewUrl);
		
		
		Menu menu = new Menu();
		menu.setButton(new Button[] { exclusiveService,imSharedButton, personCenter });
		
		
		return JsonUtils.toJson(menu);
	}
	
	private WxMpInMemoryConfigStorage getConfig(){
		WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage();
//		度益科技公众号
//	    config.setAppId("wx8a0b70c531c68f29"); // 设置微信公众号的appid
//		config.setSecret("294d5f4974ac6aea3d2b16bbac57f855"); // 设置微信公众号的app corpSecret
		
		//公司测试的公众号
//		config.setAppId("wx172faf5932aa13ff"); // 设置微信公众号的appid
//		config.setSecret("4cc16b70a113e2c569000bc76bb128f1"); // 设置微信公众号的app corpSecret
			
//		普天永利公众号
		config.setAppId("wxbd722b3620a78c59"); // 设置微信公众号的appid
		config.setSecret("78abe5212cda739455f2166fd9f7d459"); // 设置微信公众号的app corpSecret
		
		config.setToken(""); // 设置微信公众号的token
		config.setAesKey(""); // 设置微信公众号的EncodingAESKey
		
		return config;
	}
}
